#pragma once

#include <vector>
#include <Windows.h>
#include <MMSystem.h>

#include "ChordCircle.h"
#include "utils.h"


/****************
Midi player class
Midi information largely borrowed from Dr. Owen's code
****************/



class MidiPlayer
{
public:
	MidiPlayer();
	~MidiPlayer();

	void OpenMidi();
	void CloseMidi();
	void CreateChord();
	void LowerVolume();
	void RaiseVolume();
	void Fade();

	void EvalPoints();
	void DrawOverlay();

	void ClearPoints() {mPoints.clear();}
	void AddPoint(XnPoint3D point);
	void SetBestChord(double curRad);

	bool CheckTime();
	bool CheckInstr(double aX, double aY, double aZ);
	
private:
	//Device information
    HMIDIOUT mHMidiOut;     // Header to open output device

    std::vector<BYTE> mBuffer;   // Buffer to store data
    MIDIHDR      mHeader;   // Buffer header

    void NoteOn(int channel, int note, int velocity=127);
    void NoteOff(int channel, int note);

	void AllNotesOn();
	void AllNotesOff(bool All);

    void SendMidiMessage(int b0, int b1, int b2=0);

	int inst; //Instrument #
	bool on; //Whether the midi player is open
	bool playing; //Whether notes are playing...?
	std::vector<std::vector<Note> > mChord; //used to be just Keys
	//std::vector<Note> mPrevChord;
	std::vector<XnPoint3D> mPoints;
	Chords prevKey;
	Chords key;
	bool prevKeyValid;

	RECT mRC;
	int cenX, cenY;
	double minRadius, maxRadius;

	ChordCircle mCircle;

	time_t lastNote; //Do we need another time member variable (current?)
	bool replay; //If beat has passed, this is true until a new chord has played
	int mVol;
	double prevZ;
};








